home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / util / moni / Scout-src.lha / source / objects / scout_allocations.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-02-13  |  8.0 KB  |  241 lines

  1. /**
  2.  * Scout - The Amiga System Monitor
  3.  *
  4.  *------------------------------------------------------------------
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * You must not use this source code to gain profit of any kind!
  21.  *
  22.  *------------------------------------------------------------------
  23.  *
  24.  * @author Andreas Gelhausen
  25.  * @author Richard Körber <rkoerber@gmx.de>
  26.  */
  27.  
  28.  
  29.  
  30. #include "system_headers.h"
  31.  
  32. static char alcnonalc[] = "<free>";
  33. static char alcunknown[] = "<allocated>";
  34. static char alcnotavail[] = "<not available>";
  35.  
  36. static ULONG __asm __saveds __interrupt DummyIntFunc( void )
  37. {
  38.     return 0;
  39. }
  40.  
  41. static char * AlcMiscUser(ULONG unit)
  42. {
  43.   struct Library *MiscBase;
  44.   char * name;
  45.  
  46.   if(!(MiscBase = OpenResource(MISCNAME))) return(alcnotavail);
  47.  
  48.   if(!(name = AllocMiscResource(unit,"Scout")))
  49.     FreeMiscResource(unit);
  50.   return(name ? name : alcnonalc);
  51. }
  52.  
  53. static char * AlcCiaAUser(WORD unit)
  54. {
  55.   struct Library *CiaBase;
  56.   struct Interrupt DummyInt, *intr;
  57.   char * name;
  58.  
  59.   if(!(CiaBase = OpenResource(CIAANAME))) return(alcnotavail);
  60.  
  61.   memset(&DummyInt, 0x00, sizeof(struct Interrupt));
  62.   DummyInt.is_Node.ln_Type = NT_INTERRUPT;
  63.   DummyInt.is_Node.ln_Pri = -127;
  64.   DummyInt.is_Node.ln_Name = "« Scout's Dummy Int »";
  65.   DummyInt.is_Code = (void (*)())DummyIntFunc;
  66.   Disable();
  67.   if(!(intr = AddICRVector(CiaBase, unit, &DummyInt))) {
  68.     RemICRVector(CiaBase, unit, &DummyInt);
  69.     Enable();
  70.     return(alcnonalc);
  71.   }
  72.   Enable();
  73.   name = intr->is_Node.ln_Name;
  74.   return(name ? name : alcunknown);
  75. }
  76.  
  77. static char * AlcCiaBUser(WORD unit)
  78. {
  79.   struct Library *CiaBase;
  80.   struct Interrupt DummyInt, *intr;
  81.   char * name;
  82.  
  83.   if(!(CiaBase = OpenResource(CIABNAME))) return(alcnotavail);
  84.  
  85.   memset(&DummyInt, 0x00, sizeof(struct Interrupt));
  86.   DummyInt.is_Node.ln_Type = NT_INTERRUPT;
  87.   DummyInt.is_Node.ln_Pri = -127;
  88.   DummyInt.is_Node.ln_Name = "« Scout's Dummy Int »";
  89.   DummyInt.is_Code = (void (*)())DummyIntFunc;
  90.   Disable();
  91.   if(!(intr = AddICRVector(CiaBase, unit, &DummyInt))) {
  92.     RemICRVector(CiaBase, unit, &DummyInt);
  93.     Enable();
  94.     return(alcnonalc);
  95.   }
  96.   Enable();
  97.   name = intr->is_Node.ln_Name;
  98.   return(name ? name : alcunknown);
  99. }
  100.  
  101.  
  102. void PrintAllocations (char *filename) {
  103.    BPTR  handle;
  104.  
  105.    handle = HandlePrintStart (filename);
  106.    if (handle) {
  107.       if (clientstate) {
  108.          char  tmpbuffer[256];
  109.  
  110.          if (SendDaemon ("Allocations")) {
  111.             while ((sgets (client_socket, tmpbuffer, 256)) \
  112.               && (strcmp (tmpbuffer, CMD_DONE)) \
  113.               && (strcmp (tmpbuffer, CMD_ERROR))) {
  114.                PrintOneLine (handle, tmpbuffer);
  115.             }
  116.          }
  117.       } else {
  118.          if (PrintOneLine (handle, "\nCIA A:\n\n")) {
  119.             _sprintf(tmpstr2, "Timer A: %s\nTimer B: %s\n  Alarm: %s\n Serial: %s\n   Flag: %s",AlcCiaAUser(0),AlcCiaAUser(1),AlcCiaAUser(2),AlcCiaAUser(3),AlcCiaAUser(4));
  120.             PrintOneLine (handle, tmpstr2);
  121.  
  122.             PrintOneLine (handle, "\n\n\nCIA B:\n\n");
  123.             _sprintf(tmpstr2, "Timer A: %s\nTimer B: %s\n  Alarm: %s\n Serial: %s\n   Flag: %s",AlcCiaBUser(0),AlcCiaBUser(1),AlcCiaBUser(2),AlcCiaBUser(3),AlcCiaBUser(4));
  124.             PrintOneLine (handle, tmpstr2);
  125.  
  126.             PrintOneLine (handle, "\n\n\nSerial & Parallel Ports:\n\n");
  127.             _sprintf(tmpstr2, "     Serial Port: %s\n  Serial Control: %s\n   Parallel Port: %s\nParallel Control: %s",AlcMiscUser(MR_SERIALPORT),AlcMiscUser(MR_SERIALBITS),AlcMiscUser(MR_PARALLELPORT),AlcMiscUser(MR_PARALLELBITS));
  128.             PrintOneLine (handle, tmpstr2);
  129.          }
  130.       }
  131.    }
  132.    HandlePrintStop();
  133. }
  134.  
  135. void GetAllocations (void) {
  136.    if (clientstate) {
  137.       char  tmpbuffer[256];
  138.  
  139.       if (SendDaemon ("GetAlcList")) {
  140.          if (sgets (client_socket, tmpbuffer, 256)) {
  141.             MySetContents (alctext1, tmpbuffer);
  142.             if (sgets (client_socket, tmpbuffer, 256)) {
  143.                MySetContents (alctext2, tmpbuffer);
  144.                if (sgets (client_socket, tmpbuffer, 256)) {
  145.                   MySetContents (alctext3, tmpbuffer);
  146.                   if (sgets (client_socket, tmpbuffer, 256)) {
  147.                      strcmp (tmpbuffer, CMD_DONE);
  148.                   }
  149.                }
  150.             }
  151.          }
  152.       }
  153.    } else {
  154.       Forbid();
  155.       MySetContents (alctext1, "%s\n%s\n%s\n%s\n%s",AlcCiaAUser(0),AlcCiaAUser(1),AlcCiaAUser(2),AlcCiaAUser(3),AlcCiaAUser(4));
  156.       MySetContents (alctext2, "%s\n%s\n%s\n%s\n%s",AlcCiaBUser(0),AlcCiaBUser(1),AlcCiaBUser(2),AlcCiaBUser(3),AlcCiaBUser(4));
  157.       MySetContents (alctext3, "%s\n%s\n%s\n%s",AlcMiscUser(MR_SERIALPORT),AlcMiscUser(MR_SERIALBITS),AlcMiscUser(MR_PARALLELPORT),AlcMiscUser(MR_PARALLELBITS));
  158.       Permit();
  159.    }
  160. }
  161.  
  162. void SendAlcList (void) {
  163.    SendClient (ESC "r%s\n%s\n%s\n%s\n%s",AlcCiaAUser(0),AlcCiaAUser(1),AlcCiaAUser(2),AlcCiaAUser(3),AlcCiaAUser(4));
  164.    SendClient (ESC "r%s\n%s\n%s\n%s\n%s",AlcCiaBUser(0),AlcCiaBUser(1),AlcCiaBUser(2),AlcCiaBUser(3),AlcCiaBUser(4));
  165.    SendClient (ESC "r%s\n%s\n%s\n%s",AlcMiscUser(MR_SERIALPORT),AlcMiscUser(MR_SERIALBITS),AlcMiscUser(MR_PARALLELPORT),AlcMiscUser(MR_PARALLELBITS));
  166. }
  167.  
  168.  
  169. char allocations_title[WINDOWTITLELEN];
  170. static char *AllocationsPages[] = { "CIA","Ports",NULL };
  171.  
  172. void AllocationsWindow (BOOL state) {
  173.    if (state) {
  174.       if (WI_Allocations) {
  175.          GetAllocations();
  176.       } else {
  177.          WI_Allocations = WindowObject,
  178.          MUIA_Window_Title, MyGetWindowTitle (allocations_title, "ALLOCATIONS"),
  179.          MUIA_HelpNode, AllocationsText,
  180.          MUIA_Window_ID, MakeListID('A','L','L','C'),
  181.          WindowContents, VGroup,
  182.  
  183.             Child, RegisterGroup(AllocationsPages),
  184.  
  185.                Child, HGroup,
  186.                   Child, HGroup,
  187.                      GroupFrameT("CIA A"),
  188.                      Child, HGroup,
  189.                         Child, MyLabel2 (ESC "rTimer A:\nTimer B:\nAlarm:\nSerial:\nFlag:"),
  190.                         Child, alctext1 = MyTextObject(),
  191.                      End,
  192.                   End,
  193.  
  194.                   Child, HGroup,
  195.                      GroupFrameT("CIA B"),
  196.                      Child, HGroup,
  197.                         Child, MyLabel2 (ESC "rTimer A:\nTimer B:\nAlarm:\nSerial:\nFlag:"),
  198.                         Child, alctext2 = MyTextObject(),
  199.                      End,
  200.                   End,
  201.                End,
  202.  
  203.                Child, HGroup,
  204.                   GroupFrameT("Ports"),
  205.                   Child, HGroup,
  206.                      Child, MyLabel2 (ESC "rSerial Port:\nSerial Control:\nParallel Port:\nParallel Control:"),
  207.                      Child, alctext3 = MyTextObject(),
  208.                   End,
  209.                End,
  210.             End,
  211.  
  212. #ifndef WINDOW_PROBLEMS
  213.             Child, MyVSpace(4),
  214. #endif
  215.             Child, HGroup, MUIA_Group_SameSize, TRUE,
  216.                Child, BT_AlcUpdate = KeyButtonA (UpdateText,ID_ALCUPDATE),
  217.                Child, BT_AlcPrint  = KeyButtonA (PrintText ,ID_ALCPRINT),
  218.                Child, BT_AlcExit   = KeyButtonA (ExitText  ,ID_ALCEXIT),
  219.             End,
  220.          End, End;
  221.  
  222.          DoMethod (AP_Scout,OM_ADDMEMBER,WI_Allocations);
  223.          DoMethod (WI_Allocations,MUIM_Window_SetCycleChain,BT_AlcUpdate,BT_AlcPrint,BT_AlcExit,NULL);
  224.          SetCloseRequest (WI_Allocations,ID_ALCEXIT);
  225.  
  226.          GetAllocations();
  227.  
  228.          SetWindowOpen (WI_Allocations,NULL,ID_ALCEXIT);
  229.       }
  230.    } else if ((! state) && (WI_Allocations)) {
  231.       SetWindowClose (WI_Allocations,TRUE);
  232.  
  233. //      FreeAllocations();
  234.  
  235.       DoMethod (AP_Scout,OM_REMMEMBER,WI_Allocations);
  236.       MUI_DisposeObject (WI_Allocations);
  237.       WI_Allocations = NULL;
  238.    }
  239. }
  240.  
  241.